/*
 * MIT License
 * 
 * Copyright (c) 2017 wen.gu <454727014@qq.com>
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

/***************************************************************************
 * Name: vos_atomic.h
 *
 * Purpose: virtual os layer atomic operation interface 
 *
 * Developer:
 *   wen.gu , 2015-10-13
 *
 * TODO: 
 *
 ***************************************************************************/

#ifndef __VOS_ATOMIC_H__
#define __VOS_ATOMIC_H__
#include "general_type.h"

#ifdef __cplusplus
extern "C"{
#endif


/***************************************************************************
*
* macro declaration
*
***************************************************************************/

/***************************************************************************
*
* data struct declaration
*
***************************************************************************/

/***************************************************************************
*
* interface declaration
*
***************************************************************************/
/**
 *
 *@brief  add a value to orgValue as atomic operation
 *
 *@param  orgValue [io] origin value.
 *@param  addValue [in] add value.
 *
 *@return previous orgValue.
 *
 *@see    
 */
 G_API GS32 vosAtomicExchangeAdd(GS32 volatile *orgValue, GS32 addValue);

/**
 *
 *@brief  add 1 to orgValue as atomic operation
 *
 *@param  orgValue [io] origin value.
 *
 *@return previous orgValue.
 *
 *@see
 */
G_API GS32 vosAtomicIncrement(GS32 volatile *orgValue);

/**
 *
 *@brief  dec  1 from orgValue as atomic operation
 *
 *@param  orgValue [io] origin value.
 *
 *@return previous orgValue.
 *
 *@see
 */
G_API GS32 vosAtomicDecrement(GS32 volatile *orgValue);

/**
 *
 *@brief  atomic 'or' operation
 *
 *@param  orgValue [io] origin value.
 *
 *@return previous orgValue.
 *
 *@see
 */
G_API GS32 vosAtomicOr(GS32 volatile *orgValue, GS32 value);

/**
 *
 *@brief  atomic 'or' operation
 *
 *@param  orgValue [io] origin value.
 *
 *@return previous orgValue.
 *
 *@see
 */
G_API GS32 vosAtomicAnd(GS32 volatile *orgValue, GS32 value);

/**
 *
 *@brief  compare orgValue with old_value, if equal then orgValue with new_value
 *
 *@param  orgValue  [io] origin value.
 *        old_value [in] old value.
 *        new_value [in] new value.
 *
 *@return This returns true(value is 1) if the new value was successfully stored, 
 *        which will only happen when *orgValue == old_value.
 *
 *@see
 */
G_API GS32 vosAtomicCmpExchange(GS32 volatile *orgValue, GS32 old_value, GS32 new_value);

//////////////////////////////////////////////////////////////////////////
/**
 *
 *@brief  add a value to orgValue as atomic operation(orgValue is 64 bit)
 *
 *@param  orgValue [io] origin value.
 *@param  addValue [in] add value.
 *
 *@return *orgValue + addValue.
 *
 *@see    
 */
G_API GS64 vosAtomicExchangeAdd64(GS64 volatile *orgValue, GS64 addValue);

/**
 *
 *@brief  add 1 to orgValue as atomic operation(orgValue is 64 bit)
 *
 *@param  orgValue [io] origin value.
 *
 *@return previous orgValue.
 *
 *@see
 */
G_API GS64 vosAtomicIncrement64(GS64 volatile *orgValue);

/**
 *
 *@brief  dec  1 from orgValue as atomic operation(orgValue is 64 bit)
 *
 *@param  orgValue [io] origin value.
 *
 *@return previous orgValue.
 *
 *@see
 */
G_API GS64 vosAtomicDecrement64(GS64 volatile *orgValue);



#ifdef __cplusplus
}
#endif


#endif //end of __VOS_ATOMIC_H__
